package com.atguigu.hbase.mr.fruit.hdfstohbase;

import org.apache.hadoop.hbase.Cell;
import org.apache.hadoop.hbase.CellUtil;
import org.apache.hadoop.hbase.client.Put;
import org.apache.hadoop.hbase.client.Result;
import org.apache.hadoop.hbase.io.ImmutableBytesWritable;
import org.apache.hadoop.hbase.mapreduce.TableMapper;
import org.apache.hadoop.hbase.util.Bytes;
import org.apache.hadoop.io.LongWritable;
import org.apache.hadoop.io.NullWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Mapper;

import java.io.IOException;

/**
 * @ClassName FruitMapper
 * @DeScription FruitMapper
 * @Author 剧情再美终是戏
 * @Date 2019/12/9 9:58
 * @Version 1.0
 **/
public class FruitMapper extends Mapper<LongWritable, Text, NullWritable, Put> {

    ImmutableBytesWritable immutableBytesWritable = new ImmutableBytesWritable();

    //    10      ACCOUNTING      1700
//    20      RESEARCH        1800
//    30      SALES   1900
//    40      OPERATIONS      1700
    @Override
    protected void map(LongWritable key, Text value, Context context) throws IOException, InterruptedException {

        String[] split = value.toString().split("\t");

        byte[] rowkey = Bytes.toBytes(split[0]);
        immutableBytesWritable.set(rowkey);

        Put put = new Put(rowkey);

        put.addColumn(Bytes.toBytes("info"), Bytes.toBytes("deptname"), Bytes.toBytes(split[1]));
        put.addColumn(Bytes.toBytes("info"), Bytes.toBytes("num"), Bytes.toBytes(split[2]));

        context.write(NullWritable.get(), put);
    }
}
